/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.excesys.exsecs.om.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.excesys.exsecs.admin.api.entity.SysUser;
import com.excesys.exsecs.admin.api.feign.RemoteUserService;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.security.service.ExsecsUser;
import com.excesys.exsecs.common.security.util.SecurityUtils;
import com.excesys.exsecs.om.constans.OmCommonConstants;
import com.excesys.exsecs.om.dto.*;
import com.excesys.exsecs.om.entity.*;
import com.excesys.exsecs.om.mapper.*;
import com.excesys.exsecs.om.service.OmWOrderService;
import com.excesys.exsecs.om.utils.DateUtils;
import com.excesys.exsecs.om.utils.OrderNoUtils;
import com.excesys.exsecs.om.vo.HistoryVo;
import com.excesys.exsecs.om.vo.OrderVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 工单表
 *
 * @author weiyj
 * @date 2023-02-24 13:52:55
 */
@Service
@RequiredArgsConstructor
public class OmWOrderServiceImpl extends ServiceImpl<OmWOrderMapper, OmWOrder> implements OmWOrderService {

	private final OmWOrderHistoryMapper omWOrderHistoryMapper;

	private final SequenceMapper sequenceMapper;

	private final OrderNoUtils orderNoUtils;

	private final OmWOrderFileMapper omWOrderFileMapper;

	private final OmWOrderComplainMapper omWOrderComplainMapper;

	private final OmWEventMapper omWEventMapper;

	private final RemoteUserService userService;

	private final OmWOrderMapper omWOrderMapper;

	@Override
	public String getCurrentOrderNameSeq(String typeName) {
		// 生成工单号
		int order_name_seq = sequenceMapper.getSeqNextVal("order_name_seq");
		String orderNameSeq = orderNoUtils.getOrderName(typeName, order_name_seq);
		return orderNameSeq;
	}

	@Override
	public boolean saveOmWOrder(OrderDto orderDto) {
		// 生成工单号
		int orderSeq = sequenceMapper.getSeqNextVal("orderseq");
		orderDto.setOrderNo(orderNoUtils.getOrderNumber("Order", orderSeq));
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A);
		orderDto.setApplyTime(LocalDateTime.parse(LocalDateTime.now().format(formatter), formatter));
		if (null == orderDto.getHandleUserId()) {
			orderDto.setOrderStatus(OmCommonConstants.ORDER_STATUS_0);// 创建工单时没有选择了处理人
																		// 就是待指派状态
		}
		else {
			orderDto.setOrderStatus(OmCommonConstants.ORDER_STATUS_1);// 创建工单时选择了处理人
																		// 就是待处理状态
		}

		OmWOrder omWOrder = new OmWOrder();
		BeanUtils.copyProperties(orderDto, omWOrder);
		OmWOrderHistory omWOrderHistory = new OmWOrderHistory();
		omWOrderHistory.setOperation("创建工单");
		ExsecsUser ExsecsUser = SecurityUtils.getUser();
		// 工单报告人信息
		omWOrder.setOrderUserDeptId(ExsecsUser.getDeptId());
		omWOrder.setOrderUserId(ExsecsUser.getId());
		omWOrder.setOrderUserName(ExsecsUser.getName());
		omWOrder.setOrderUserPhone(ExsecsUser.getPhone());

		omWOrderHistory.setOperateUserId(ExsecsUser.getId());
		omWOrderHistory.setOperateDeptId(ExsecsUser.getDeptId());
		omWOrderHistory.setOrderNo(orderDto.getOrderNo());
		omWOrderHistory.setEventNo(orderDto.getEventNo());
		omWOrderHistoryMapper.insert(omWOrderHistory);
		// orderDto.setApplyTime(LocalDateTime.parse(LocalDateTime.now().toString(),
		// DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A)));
		// 保存工单附件信息

		Optional.ofNullable(orderDto.getFileList()).ifPresent(fileLists -> {
			fileLists.stream().map(omWOrderFile -> {
				omWOrderFile.setOrderNo(orderDto.getOrderNo());
				return omWOrderFile;
			}).forEach(omWOrderFileMapper::insert);
		});
		return SqlHelper.retBool(this.getBaseMapper().insert(omWOrder));
	}

	@Override
	public boolean saveRepairOmWOrder(OrderDto orderDto) {
		// 生成工单号
		int orderSeq = sequenceMapper.getSeqNextVal("orderseq");
		orderDto.setOrderNo(orderNoUtils.getOrderNumber("Order", orderSeq));
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A);
		orderDto.setApplyTime(LocalDateTime.parse(LocalDateTime.now().format(formatter), formatter));
		if (null == orderDto.getHandleUserId()) {
			orderDto.setOrderStatus(OmCommonConstants.ORDER_STATUS_0);// 创建工单时没有选择了处理人
																		// 就是待指派状态
		}
		else {
			orderDto.setOrderStatus(OmCommonConstants.ORDER_STATUS_1);// 创建工单时选择了处理人
																		// 就是待处理状态
		}

		OmWOrder omWOrder = new OmWOrder();
		BeanUtils.copyProperties(orderDto, omWOrder);
		OmWOrderHistory omWOrderHistory = new OmWOrderHistory();
		omWOrderHistory.setOperation("创建工单");
		ExsecsUser ExsecsUser = SecurityUtils.getUser();
		// 工单报告人信息
		omWOrder.setOrderUserDeptId(ExsecsUser.getDeptId());
		omWOrder.setOrderUserId(ExsecsUser.getId());
		omWOrder.setOrderUserName(ExsecsUser.getName());
		omWOrder.setOrderUserPhone(ExsecsUser.getPhone());
		omWOrder.setRepairType("1");
		omWOrderHistory.setOperateUserId(ExsecsUser.getId());
		omWOrderHistory.setOperateDeptId(ExsecsUser.getDeptId());
		omWOrderHistory.setOrderNo(orderDto.getOrderNo());
		omWOrderHistory.setEventNo(orderDto.getEventNo());
		omWOrderHistoryMapper.insert(omWOrderHistory);
		// orderDto.setApplyTime(LocalDateTime.parse(LocalDateTime.now().toString(),
		// DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A)));
		// 保存工单附件信息

		Optional.ofNullable(orderDto.getFileList()).ifPresent(fileLists -> {
			fileLists.stream().map(omWOrderFile -> {
				omWOrderFile.setOrderNo(orderDto.getOrderNo());
				return omWOrderFile;
			}).forEach(omWOrderFileMapper::insert);
		});
		return SqlHelper.retBool(this.getBaseMapper().insert(omWOrder));
	}

	@Override
	public boolean saveMaintenanceOmWOrder(OrderDto orderDto) {
		// 生成工单号
		int orderSeq = sequenceMapper.getSeqNextVal("orderseq");
		orderDto.setOrderNo(orderNoUtils.getOrderNumber("Order", orderSeq));
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A);
		orderDto.setApplyTime(LocalDateTime.parse(LocalDateTime.now().format(formatter), formatter));
		if (null == orderDto.getHandleUserId()) {
			orderDto.setOrderStatus(OmCommonConstants.ORDER_STATUS_0);// 创建工单时没有选择了处理人
																		// 就是待指派状态
		}
		else {
			orderDto.setOrderStatus(OmCommonConstants.ORDER_STATUS_1);// 创建工单时选择了处理人
																		// 就是待处理状态
		}

		OmWOrder omWOrder = new OmWOrder();
		BeanUtils.copyProperties(orderDto, omWOrder);
		OmWOrderHistory omWOrderHistory = new OmWOrderHistory();
		omWOrderHistory.setOperation("创建工单");
		ExsecsUser ExsecsUser = SecurityUtils.getUser();
		// 工单报告人信息
		omWOrder.setOrderUserDeptId(ExsecsUser.getDeptId());
		omWOrder.setOrderUserId(ExsecsUser.getId());
		omWOrder.setOrderUserName(ExsecsUser.getName());
		omWOrder.setOrderUserPhone(ExsecsUser.getPhone());
		omWOrder.setRepairType("2");
		omWOrderHistory.setOperateUserId(ExsecsUser.getId());
		omWOrderHistory.setOperateDeptId(ExsecsUser.getDeptId());
		omWOrderHistory.setOrderNo(orderDto.getOrderNo());
		omWOrderHistory.setEventNo(orderDto.getEventNo());
		omWOrderHistoryMapper.insert(omWOrderHistory);
		// orderDto.setApplyTime(LocalDateTime.parse(LocalDateTime.now().toString(),
		// DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A)));
		// 保存工单附件信息

		Optional.ofNullable(orderDto.getFileList()).ifPresent(fileLists -> {
			fileLists.stream().map(omWOrderFile -> {
				omWOrderFile.setOrderNo(orderDto.getOrderNo());
				return omWOrderFile;
			}).forEach(omWOrderFileMapper::insert);
		});
		return SqlHelper.retBool(this.getBaseMapper().insert(omWOrder));
	}

	@Override
	public boolean updateOmWOrder(OrderDto orderDto) {
		OmWOrder omWOrder = new OmWOrder();
		BeanUtils.copyProperties(orderDto, omWOrder);
		OmWOrderHistory omWOrderHistory = new OmWOrderHistory();
		omWOrderHistory.setOperation("修改工单");
		ExsecsUser ExsecsUser = SecurityUtils.getUser();
		omWOrderHistory.setOperateUserId(ExsecsUser.getId());
		omWOrderHistory.setOperateDeptId(ExsecsUser.getDeptId());
		omWOrderHistory.setOrderNo(omWOrder.getOrderNo());
		omWOrderHistory.setEventNo(omWOrder.getEventNo());
		omWOrderHistoryMapper.insert(omWOrderHistory);
		omWOrderFileMapper
				.delete(Wrappers.<OmWOrderFile>update().lambda().eq(OmWOrderFile::getOrderNo, orderDto.getOrderNo()));
		Optional.ofNullable(orderDto.getFileList()).ifPresent(fileLists -> {
			fileLists.stream().map(omWOrderFile -> {
				omWOrderFile.setOrderNo(orderDto.getOrderNo());
				return omWOrderFile;
			}).forEach(omWOrderFileMapper::insert);
		});
		return SqlHelper.retBool(this.getBaseMapper().updateById(omWOrder));
	}

	@Override
	public boolean removeOmWOrderById(Serializable id) {
		OmWOrder omWOrder = this.getById(id);
		OmWOrderHistory omWOrderHistory = new OmWOrderHistory();
		omWOrderHistory.setOperation("删除工单");
		ExsecsUser ExsecsUser = SecurityUtils.getUser();
		omWOrderHistory.setOperateUserId(ExsecsUser.getId());
		omWOrderHistory.setOperateDeptId(ExsecsUser.getDeptId());
		omWOrderHistory.setOrderNo(omWOrder.getOrderNo());
		omWOrderHistory.setEventNo(omWOrder.getEventNo());
		omWOrderHistoryMapper.insert(omWOrderHistory);
		return SqlHelper.retBool(this.getBaseMapper().deleteById(id));
	}

	/**
	 * 分页查询工单信息（含有历史 处理信息）
	 * @param page 分页对象
	 * @param omWOrder 参数列表
	 * @return
	 */
	@Override
	public IPage<OrderVo> getOrderWithRelPage(Page page, OmWOrder omWOrder, String flag) {
		IPage<OrderVo> iPage = new Page<>();
		if ("1".equals(flag))
			iPage = baseMapper.getOrderWithRelTodayPage(page, omWOrder);
		else
			iPage = baseMapper.getOrderWithRelPage(page, omWOrder);
        if(ObjectUtil.isNotEmpty(omWOrder) ){
			if(ObjectUtil.isNotEmpty(omWOrder.getEvaluateFlag())){
			if(!omWOrder.getEvaluateFlag().equals("1")) {
				for (OrderVo record : iPage.getRecords()) {
					for (HistoryVo historyVo : record.getHistoryList()) {
						if (null != historyVo.getOperateUserId()) {
							R<SysUser> userInfo = userService.getUserById(historyVo.getOperateUserId());
							if (null != userInfo.getData()) {
								historyVo.setOperateUserName(userInfo.getData().getName());
							}
						}
					}
				}
			}
			}
		}
		return iPage;
	}

	/**
	 * 分页查询工单信息（含有历史 处理信息）
	 * @param page 分页对象
	 * @param omWOrder 参数列表
	 * @return
	 */
	@Override
	public IPage<OrderVo> getRepairOrderWithRelPage(Page page, OmWOrder omWOrder, String flag) {
		IPage<OrderVo> iPage = new Page<>();
		if ("1".equals(flag))
			iPage = baseMapper.getRepairOrderWithRelTodayPage(page, omWOrder);
		else
			iPage = baseMapper.getRepairOrderWithRelPage(page, omWOrder);
		for (OrderVo record : iPage.getRecords()) {
			for (HistoryVo historyVo : record.getHistoryList()) {
				if (null != historyVo.getOperateUserId()) {
					R<SysUser> userInfo = userService.getUserById(historyVo.getOperateUserId());
					if (null != userInfo.getData()) {
						historyVo.setOperateUserName(userInfo.getData().getName());
					}
				}
			}
		}
		return iPage;
	}

	@Override
	public IPage<OrderVo> getMintenanceOrderWithRelPage(Page page, OmWOrder omWOrder, String flag) {
		IPage<OrderVo> iPage = new Page<>();
		if ("1".equals(flag))
			iPage = baseMapper.getMaintenanceOrderWithRelTodayPage(page, omWOrder);
		else
			iPage = baseMapper.getMaintenanceOrderWithRelPage(page, omWOrder);
		for (OrderVo record : iPage.getRecords()) {
			for (HistoryVo historyVo : record.getHistoryList()) {
				if (null != historyVo.getOperateUserId()) {
					R<SysUser> userInfo = userService.getUserById(historyVo.getOperateUserId());
					if (null != userInfo.getData()) {
						historyVo.setOperateUserName(userInfo.getData().getName());
					}
				}
			}
		}
		return iPage;
	}

	@Override
	public IPage<OrderVo> getPage(Page page, OmWOrder omWOrder) {
		IPage<OrderVo> iPage = baseMapper.getOrderWithRel8Page(page, omWOrder);
		for (OrderVo record : iPage.getRecords()) {
			for (HistoryVo historyVo : record.getHistoryList()) {
				if (null != historyVo.getOperateUserId()) {
					R<SysUser> userInfo = userService.getUserById(historyVo.getOperateUserId());
					if (null != userInfo.getData()) {
						historyVo.setOperateUserName(userInfo.getData().getName());
					}
				}
			}
		}
		return iPage;
	}

	@Override
	public IPage<OrderVo> getRepairPage(Page page, OmWOrder omWOrder) {
		IPage<OrderVo> iPage = baseMapper.getRepairOrderWithRel8Page(page, omWOrder);
		for (OrderVo record : iPage.getRecords()) {
			for (HistoryVo historyVo : record.getHistoryList()) {
				if (null != historyVo.getOperateUserId()) {
					R<SysUser> userInfo = userService.getUserById(historyVo.getOperateUserId());
					if (null != userInfo.getData()) {
						historyVo.setOperateUserName(userInfo.getData().getName());
					}
				}
			}
		}
		return iPage;
	}

	@Override
	public IPage<OrderVo> getMaintenancePage(Page page, OmWOrder omWOrder) {
		IPage<OrderVo> iPage = baseMapper.getMaintenanceOrderWithRel8Page(page, omWOrder);
		for (OrderVo record : iPage.getRecords()) {
			for (HistoryVo historyVo : record.getHistoryList()) {
				if (null != historyVo.getOperateUserId()) {
					R<SysUser> userInfo = userService.getUserById(historyVo.getOperateUserId());
					if (null != userInfo.getData()) {
						historyVo.setOperateUserName(userInfo.getData().getName());
					}
				}
			}
		}
		return iPage;
	}

	/**
	 * 工单操作
	 * @param orderHistoryDto 参数列表
	 * @return
	 */
	@Override
	public R<Boolean> operateOmWOrder(OrderHistoryDto orderHistoryDto) {

		String orderStatus = orderHistoryDto.getOrderStatus();

		Boolean isok = true;
		String returnMsg = "";

		OmWOrder omWOrder = new OmWOrder();
		omWOrder.setOrderNo(orderHistoryDto.getOrderNo());
		omWOrder = this.getOne(new QueryWrapper<>(omWOrder));

		// 补全history信息
		ExsecsUser ExsecsUser = SecurityUtils.getUser();
		orderHistoryDto.setOperateUserId(ExsecsUser.getId());
		orderHistoryDto.setOperateDeptId(ExsecsUser.getDeptId());
		orderHistoryDto.setHandleUserDeptId(ExsecsUser.getDeptId());
		orderHistoryDto.setEventNo(omWOrder.getEventNo());

		String operation = "";
		// 指派工单
		if (orderStatus.equals("1")) {
			// 管理员和服务台进入未指派、已指派、处理中、挂起状态的工单详情进行指派或重新选择处理企业和处理人
			if (omWOrder.getOrderStatus().equals("0") || omWOrder.getOrderStatus().equals("1")
					|| omWOrder.getOrderStatus().equals("2") || omWOrder.getOrderStatus().equals("4")) {
				omWOrder.setOrderStatus(orderStatus);
				omWOrder.setHandleUserDeptId(orderHistoryDto.getHandleUserDeptId());
				omWOrder.setHandleUserId(orderHistoryDto.getHandleUserId());

				R<SysUser> userInfo = userService.getUserById(orderHistoryDto.getHandleUserId());
				omWOrder.setHandleUserName(userInfo.getData().getName());
				omWOrder.setHandleUserPhone(userInfo.getData().getPhone());

				this.getBaseMapper().updateById(omWOrder);
				returnMsg = "工单已指派";
				operation = "指派工单";
			}
			else {
				isok = false;
				returnMsg = "工单当前状态不能指派";
			}

		}

		// 接单
		if (orderStatus.equals("2")) {
			omWOrder.setOrderStatus(orderStatus);
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "工单已接单";
			operation = "接单";
		}
		// 签到出发
		if (orderStatus.equals("3")) {
			omWOrder.setOrderStatus(orderStatus);
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "签到出发";
			operation = "签到出发";
		}

		// 挂起工单
		if (orderStatus.equals("4")) {
			omWOrder.setOrderStatus(orderStatus);
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "工单已挂起";
			operation = "挂起工单";
		}

		// 挂起工单
		if (orderStatus.equals("5")) {
			omWOrder.setOrderStatus(orderStatus);
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "到达";
			operation = "到达";
		}

		// 处理工单
		if (orderStatus.equals("6")) {
			omWOrder.setOrderStatus(orderStatus);
			omWOrder.setHandleUserDeptId(ExsecsUser.getDeptId());
			omWOrder.setHandleUserId(ExsecsUser.getId());
			omWOrder.setHandleUserName(ExsecsUser.getName());
			omWOrder.setHandleUserPhone(ExsecsUser.getPhone());
			omWOrder.setHandleTime(
					LocalDateTime.parse(DateUtil.now(), DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A)));
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "工单已处理";
			operation = "处理工单";
		}

		// 评价工单
		if (orderStatus.equals("7")) {
			omWOrder.setOrderStatus(orderStatus);
			omWOrder.setEvaluateUserId(ExsecsUser.getId());
			omWOrder.setEvaluateFlag(OmCommonConstants.EVALUTE_FLAG_1);
			omWOrder.setEvaluation(orderHistoryDto.getEvaluation());
			omWOrder.setSatisfaction(orderHistoryDto.getSatisfaction());
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "工单已确认";
			operation = "确认工单";
		}

		// 关闭工单
		if (orderStatus.equals("8")) {
			omWOrder.setOrderStatus(orderStatus);
			this.getBaseMapper().updateById(omWOrder);
			String eventNo = omWOrder.getEventNo();

			// 如果有事件编号关闭对应的事件
			if (StrUtil.isNotEmpty(eventNo)) {
				OmWEvent omWEvent = new OmWEvent();
				omWEvent.setEventNo(eventNo);
				omWEvent = omWEventMapper.selectOne(new QueryWrapper<>(omWEvent));
				omWEvent.setEventStatus(OmCommonConstants.EVENT_STATUS_4);
				omWEventMapper.updateById(omWEvent);
			}
			returnMsg = "工单已关闭";
			operation = "关闭工单";
		}

		// 取消工单
		if (orderStatus.equals("9")) {
			omWOrder.setOrderStatus(orderStatus);
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "取消工单";
			operation = "取消工单";
		}

		// 投诉工单
		if (orderStatus.equals("10")) {
			OmWOrderComplain omWOrderComplain = new OmWOrderComplain();
			omWOrderComplain.setOrderNo(omWOrder.getOrderNo());
			omWOrderComplain.setComplainUserId(ExsecsUser.getId());
			omWOrderComplain.setComplainName(ExsecsUser.getName());
			omWOrderComplain.setComplainPhone(ExsecsUser.getPhone());
			omWOrderComplain.setComplainTime(
					LocalDateTime.parse(DateUtil.now(), DateTimeFormatter.ofPattern(DateUtils.DATE_FORMATE_STRING_A)));
			omWOrderComplain.setComplainDesc(orderHistoryDto.getRemark());
			omWOrderComplain.setComplainState(OmCommonConstants.COMPLAIN_STATE_0);// 待指派
			omWOrderComplainMapper.insert(omWOrderComplain);
			returnMsg = "工单已投诉";
			operation = "投诉工单";
		}

		// 激活
		if (orderStatus.equals("11")) {
			omWOrder.setOrderStatus(OmCommonConstants.ORDER_STATUS_1);
			this.getBaseMapper().updateById(omWOrder);
			returnMsg = "工单已激活";
			operation = "激活工单";
		}

		OmWOrderHistory omWOrderHistory = new OmWOrderHistory();
		BeanUtils.copyProperties(orderHistoryDto, omWOrderHistory);
		omWOrderHistory.setOperation(operation);
		omWOrderHistoryMapper.insert(omWOrderHistory);

		return R.ok(isok, returnMsg);
	}

	@Override
	public Map<String, String> getOrderCountMap(Long userId, Long createUserId, Long evaluateUserId) {
		return this.getBaseMapper().getOrderCountMap(userId, createUserId, evaluateUserId);
	}

	@Override
	public Map<String, String> getOrderCountByTimeType(String timeType) {
		return this.getBaseMapper().getOrderCountByTimeType(timeType);
	}

	@Override
	public List<Map<String, String>> getOrderCountByYearMonth() {
		return this.getBaseMapper().getOrderCountByYearMonth();
	}

	@Override
	public List<Map<String, String>> getOrderCountByDeviceType(String month) {
		return this.getBaseMapper().getOrderCountByDeviceType(month);
	}

	@Override
	public Map<String, Map<String, String>> getOrderSize() {
		Map<String, Map<String, String>> countMap = new HashMap<>();
		Map<String, String> yearMap = omWOrderMapper.getOrderByYear();
		Map<String, String> mouthMap = omWOrderMapper.getOrderByMouth();
		Map<String, String> dayMap = omWOrderMapper.getOrderByDay();
		countMap.put("yearMap", yearMap);
		countMap.put("mouthMap", mouthMap);
		countMap.put("dayMap", dayMap);

		// //未指派-0 已指派-1 处理中-2 出发中-3 挂起-4 已到达-5 已处理-6 已解决-7 已关闭-8 已取消-9 总数
		return countMap;
	}

	@Override
	public List<WarrantyDto> getWarrantyMethod() {
		List<WarrantyDto> list = new ArrayList<>();
		WarrantyDto warrantyDto = new WarrantyDto();
		List<WarrantyMethodDto> yearList = new ArrayList<>();
		List<WarrantyMethodDto> mouthList = new ArrayList<>();
		List<WarrantyMethodDto> dayList = new ArrayList<>();
		Map<String, BigDecimal> yearMap = omWOrderMapper.getWarrantyByYear();
		for (Map.Entry<String, BigDecimal> map : yearMap.entrySet()) {
			WarrantyMethodDto warrantyMethodDto = new WarrantyMethodDto();
			warrantyMethodDto.setName(map.getKey());
			warrantyMethodDto.setValue(map.getValue());
			yearList.add(warrantyMethodDto);
		}
		Map<String, BigDecimal> mouthMap = omWOrderMapper.getWarrantyByMouth();
		for (Map.Entry<String, BigDecimal> map : mouthMap.entrySet()) {
			WarrantyMethodDto warrantyMethodDto = new WarrantyMethodDto();
			warrantyMethodDto.setName(map.getKey());
			warrantyMethodDto.setValue(map.getValue());
			mouthList.add(warrantyMethodDto);
		}
		Map<String, BigDecimal> dayMap = omWOrderMapper.getWarrantyByDay();
		for (Map.Entry<String, BigDecimal> map : dayMap.entrySet()) {
			WarrantyMethodDto warrantyMethodDto = new WarrantyMethodDto();
			warrantyMethodDto.setName(map.getKey());
			warrantyMethodDto.setValue(map.getValue());
			dayList.add(warrantyMethodDto);
		}
		warrantyDto.setDayList(dayList);
		warrantyDto.setMouthList(mouthList);
		warrantyDto.setYearList(yearList);
		list.add(warrantyDto);
		return list;
	}

	@Override
	public List<RepairDto> getRepairList() {
		List<RepairDto> list = new ArrayList<>();
		RepairDto repairDto = new RepairDto();
		// 今年
		List<WarrantyMethodDto> yearList = omWOrderMapper.getRepairByYear();
		// 去年
		List<WarrantyMethodDto> lastYearList = omWOrderMapper.getRepairByLastYear();

		// 本月
		List<WarrantyMethodDto> monthList = omWOrderMapper.getRepairByMonth();
		// 上月
		List<WarrantyMethodDto> lastMonthList = omWOrderMapper.getRepairByLastMonth();

		// 今天
		List<WarrantyMethodDto> todayList = omWOrderMapper.getRepairByToday();
		// 昨天
		List<WarrantyMethodDto> yesterdayList = omWOrderMapper.getRepairByYesterday();
		repairDto.setYearList(yearList);
		repairDto.setLastYearList(lastYearList);
		repairDto.setMonthList(monthList);
		repairDto.setLastMonthList(lastMonthList);
		repairDto.setTodayList(todayList);
		repairDto.setYesterdayList(yesterdayList);
		list.add(repairDto);
		return list;
	}

	@Override
	public OmWOrder getByOrderNo(String no) {
		return omWOrderMapper.getByOrderNo(no);
	}

	@Override
	public IPage<OmWOrder> getHomepage(Page page, OmWOrder omWOrder) {
		return this.baseMapper.getHomepage(page,omWOrder);
	}

}
